package org.example.Future;

/*
包装类
 */
public class FutureDate implements Date {

    private RealDate realDate;
    private boolean isReady = false;//数据是否装载完毕
    public synchronized void setRealDate(RealDate realDate){
        //如果装在完毕，就直接返回
        if (isReady){
            return;
        }
        this.realDate = realDate;
        this.isReady = true;
        //进行通知
        notify();
    }

    //获取数据，确保时候装载好了真实数据
    @Override
    public synchronized String getRequest() {
        //获取数据，判断是否装载好了真实水，如果没有装载好，程序就一直处于阻塞状态
        while (!isReady){
            try {
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        return this.realDate.getRequest();
    }


}
